package view;

import java.util.Observable;

import javax.swing.Icon;
import javax.swing.SwingConstants;

import org.jdesktop.swingx.JXButton;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;
import component.Icons;

import control.OpenBookOverviewAction;
import control.OpenCustomerOverviewAction;
import control.OpenLoanOverviewAction;
import domain.Library;

@SuppressWarnings("serial")
public class LibraryMainJPanel extends AbstractContentJPanel {
	private Library lib;
	public LibraryMainJPanel(LibraryMainJFrame mainFrame) {
		super(mainFrame);
		lib = Library.getInstance();
		lib.addObserver(this);
		initGUI();
	}
	
	@Override
	public String getName(){
		return "Start";
	}
	
	@Override
	public Icon getIcon(){
		return Icons.HOME;
	}
	
	@Override
	public boolean isCloseable(){
		return false;
	}

	private void initGUI() {
		setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.GROWING_BUTTON_COLSPEC,
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				FormFactory.GROWING_BUTTON_COLSPEC,
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				FormFactory.GROWING_BUTTON_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,},
			new RowSpec[] {
				FormFactory.LINE_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("fill:23px:grow"),
				FormFactory.RELATED_GAP_ROWSPEC,
				RowSpec.decode("default:grow"),}));
		
		JXButton lblBcher = new JXButton(new OpenBookOverviewAction(mainFrame));
		lblBcher.setHorizontalAlignment(SwingConstants.CENTER);
		
		add(lblBcher, "3, 4, fill, fill");

		JXButton lblKunden = new JXButton(new OpenCustomerOverviewAction(mainFrame));
		lblKunden.setHorizontalAlignment(SwingConstants.CENTER);
		
		add(lblKunden, "5, 4, fill, fill");

		JXButton lblAusleihen = new JXButton(new OpenLoanOverviewAction(mainFrame));
		lblAusleihen.setHorizontalAlignment(SwingConstants.CENTER);
		
		add(lblAusleihen, "7, 4, fill, fill");

	}


	@Override
	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub

	}

	public void openBookDetailOverview() {
		this.mainFrame.openContentPanel(new BookOverviewJPanel(mainFrame));
	}

}
